<template>
<h2>员工列表练习</h2>
  <el-form label-width="100px">
    <el-form-item label="姓名">
      <el-input v-model="emp.name" placeholder="placeholder"></el-input>
    </el-form-item>
    <el-form-item label="工资">
      <el-input v-model="emp.salary" placeholder="placeholder"></el-input>
    </el-form-item>
    <el-form-item label="工作">
      <el-input v-model="emp.job" placeholder="placeholder"></el-input>
    </el-form-item>
    <el-form-item><el-button @click="add()">添加</el-button></el-form-item>
  </el-form>
  <el-table :data="arr">
    <el-table-column type="index" width="80px" label="编号"></el-table-column>
    <el-table-column prop="name" width="100px" label="姓名"></el-table-column>
    <el-table-column prop="salary" width="100px" label="工资"></el-table-column>
    <el-table-column prop="job" label="工作"></el-table-column>
    <el-table-column label="操作">
      <template #default="scope">
        <el-button type="danger" @click="del(scope.$index,scope.row)">删除</el-button>
      </template>
    </el-table-column>
  </el-table>
</template>

<script setup>
import {ref} from "vue";

const del = (i,emp) =>{
  if (confirm("你确认删除"+emp.name+"吗?")){
    arr.value.splice(i,1);
  }
}
const emp = ref({name:"",salary:"",job:""});
const arr = ref([]);
const add = ()=>{
  arr.value.push({...emp.value});
}

</script>

<style scoped>

</style>